define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'cdr/index',
                    add_url: 'cdr/add',
                    edit_url: 'cdr/edit',
                    del_url: 'cdr/del',
                    multi_url: 'cdr/multi',
                    table: 'cdr',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'merid', title: __('Merid')},
                        {field: 'uid', title: __('Uid')},
                        {field: 'caller', title: __('Caller')},
                        {field: 'callee', title: __('Callee')},
                        {field: 'route', title: __('Route')},
                        {field: 'calltype', title: __('Calltype')},
                        {field: 'starttime', title: __('Starttime'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'responsetime', title: __('Responsetime'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'answertime', title: __('Answertime'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'endtime', title: __('Endtime'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'fee', title: __('Fee')},
                        {field: 'cost', title: __('Cost')},
                        //{field: 'minutes', title: __('Minutes')},
                        {field: 'duration', title: __('Duration')},
                        {field: 'billsec', title: __('Billsec')}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});